<template>
  <div class="dataManage">
    <nav-bar class="home-nav">
      <div class="left" slot="left" @click="goBack">
        <van-icon name="arrow-left" size="24"/>
      </div>
      <div slot="center">用户查询</div>
    </nav-bar>

    <div class="search">
      <div class="search_select">
        <van-field
          readonly
          clickable
          right-icon="arrow-down"
          name="picker"
          :value="city"
          label=""
          placeholder="全部地区"
          @click="showArea = true"
        />
      </div>
      <div class="search_input">
        <van-search
          v-model="nickname"
          shape="round"
          background="#ffffff"
          placeholder="请输入搜索关键词"
          @search="onSearch"
        />
      </div>

      <van-popup v-model="showArea" position="bottom">
        <van-area title="标题" :area-list="areaList" :columns-num="2" @confirm="onConfirm" @cancel="showArea = false"/>
      </van-popup>

    </div>

    <div class="search-item" v-for="item in userLists">
      <div class="search-item-top">
        <img :src="item.headimgurl"/>
        <div class="search-item-text">
          <span class="user_name">{{item.nickname}}</span>
          <span class="user_other" v-if="item.sex == 1">
            男
            </span>
          <span class="user_other" v-else-if="item.sex == 2">
            女
            </span>
          <span class="user_other" v-else>
            未知
            </span>
          <span class="user_other">{{item.country}} {{item.province}} {{item.city}}</span>
        </div>
      </div>
      <div class="date">查询时间：{{item.create_date}}</div>
    </div>

  </div>
</template>

<script>
  import areaList from "@/common/area";
  import NavBar from "@/components/common/navbar/NavBar";

  export default {
    name: "list",
    components: {
      NavBar,
    },

    data() {
      return {
        batch_id: '',
        nickname: '',
        showArea: false,
        areaList: '',
        province: '',
        city: '',
        userLists: '',
      }
    },

    created() {
      this.batch_id = this.$route.query.batch_id;
      this.areaList = areaList;
      this.getUserLists();
    },

    methods: {
      onSearch(val) {
        console.log(val);
      },

      getUserLists() {
        let that = this;
        let params = {
          batch_id: that.batch_id,
          province: that.province,
          city: that.city,
          nickname: that.nickname
        };
        console.log('params', params);
        that.$http.get('/api/MobileAadminApi/getCheckUserList', params, r => {
          console.log('用户结果：', r)
          that.userLists = r.data;
        })
      },

      onConfirm(values) {
        console.log(values)
        this.province = values[0].name;
        this.city = values[1].name;
        //this.value = values.map((item) => item.name).join('/');
        this.showArea = false;
        this.getUserLists();
      },

      goBack() {
        this.$router.go(-1);
      },

    }
  }
</script>

<style scoped>
  .search-item {
    margin: 10px;
    background: #ffffff;
    border-radius: 8px;
  }

  .search-item-top {
    display: flex;
    padding: 10px;
    border-bottom: 1px solid #eeeeee;
  }

  .search-item-top img {
    width: 1rem;
    height: 1rem;
    border-radius: 50%;
  }

  .search-item-text {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding-left: 10px;
  }
  .search_input >>> .van-cell, .search_select >>> .van-cell {
    font-size: .28rem;
    padding:.1rem;
  }
  .user_name {
    font-size: .28rem;
  }

  .user_other {
    font-size: .24rem;
  }

  .date {
    font-size: .3rem;
    padding: 7px 10px;
  }
</style>
